package com.gxa.meiye.admin.shop.controller;

import com.gxa.meiye.admin.shop.service.EditPwdService;
import com.gxa.meiye.core.common.ResponseData;
import com.gxa.meiye.core.pojo.shopManagement.Shop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author cc
 * @PackageName meiye
 * @Package com.gxa.meiye.admin.shop.controller
 * @Date 2022/7/25 13:59
 * @Version 1.0
 */
@RestController
@Api(tags = "修改密码接口")
@RequestMapping("editPwd")
public class AdminEditPwdController {
    @Autowired
    private EditPwdService editPwdService;

    @PostMapping("editPwd")
    @ApiOperation("根据邮箱修改密码")
    public ResponseData updatePassword(Shop shop) {
        ResponseData rd = new ResponseData();
        String pwd = shop.getPwd();
        String email = shop.getEmail();
        SimpleHash simpleHash = new SimpleHash("MD5",pwd,email,1024);
        String MD5pwd = simpleHash.toString();
        shop.setPwd(MD5pwd);
        String checkPwd = editPwdService.queryPwdByEmail(shop);
        if(!MD5pwd.equals(checkPwd)){
            rd.setCode(500);
            rd.setMsg("原密码错误");
        }else{
            String newPwd = shop.getNewPwd();
            SimpleHash simpleHash1 = new SimpleHash("MD5",newPwd,email,1024);
            String MD5pwd1= simpleHash1.toString();
            shop.setPwd(MD5pwd1);
            editPwdService.editPwdByEmail(shop);
            rd.setCode(200);
            rd.setMsg("修改密码成功");
        }
        return rd;

    }


}